package com.smartEdu.controller;

import org.apache.thrift.TException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.smartEdu.module.thrift.client.helloworld.HelloWorldTClient;
import com.smartEdu.module.thrift.server.helloworld.HelloWorldServer;
import com.smartEdu.module.thrift.server.helloworld.HelloWorldService;

@Controller
public class ThriftTestController {
	@Autowired
	@Qualifier(value="HelloWorldTClient")
	private HelloWorldTClient client;
	
//	@Autowired
//	private HelloWorldServer server;
	
	@RequestMapping(value="clientsend") 
	public void test() {
		System.out.println("访问Test");
		HelloWorldService.Client serviceClient = client.getClient();
		try {
			client.open();
			System.err.println(serviceClient.sayHello("你好"));
			client.close();
			System.out.println("正常结束");
		} catch (TException e) {
			e.printStackTrace();
		}
	}
	
	@RequestMapping(value="serverclose") 
	public void close() {
		try {
//			server.stop();
			System.out.println("正常关闭");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	@RequestMapping(value="closejvm") 
	public void closeJvm() {
		try {
			System.exit(1);
			System.out.println("JVM关闭");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
